package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IBackwork;
import com.example.mymatch.model.Backwork;
import com.example.mymatch.service.IBackworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：杨滢
 */

@Service
public class IBackworkServiceImpl implements IBackworkService {
    @Autowired
    private IBackwork backworkMapper;

    @Override
    public int insertBackwork(Backwork backwork){
        int backworkValue=0;
        //查看当前用户名称不能重复
        Backwork backwork1=new Backwork();
        backwork1.setBackName(backwork.getBackName());
        List<Backwork> getC=backworkMapper.getAllBackwork(backwork1);
        if (getC.size()>=1){
            //不可以添加用户名称
            backworkValue=-1;
        }else {
            backworkValue=backworkMapper.insertBackwork(backwork);
        }
        return backworkValue;
    }

    @Override
    public List<Backwork> getAllBackwork(Backwork backwork){
        return backworkMapper.getAllBackwork(backwork);
    }

    @Override
    public int updateBackwork(Backwork backwork){
        int backworkValue=0;
        //判断主键不能为0
        if (backwork.getId()!=0){
            //主键信息必修存在
            //名称不能重复
            backworkValue=backworkMapper.updateBackwork(backwork);
        }
        return backworkValue;
    }

    @Override
    public  int deleteBackwork(Backwork backwork){
        int backworkValue=0;
        //判断主键不能为0
        if (backwork.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除
            backworkValue=backworkMapper.deleteBackwork(backwork);
        }
        return backworkValue;
    }

    //单条查询
    @Override
    public Backwork getBackwork(Backwork backwork){
        Backwork backwork1=new Backwork();
        if (backwork.getId()!=0){
            backwork1=backworkMapper.getBackwork(backwork);
        }
        return backwork1;
    }
}
